//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/.
// 			VisualNovelToolkit		     /_/_/_/_/_/_/_/_/_/.
// Copyright ©2013 - Sol-tribe.	/_/_/_/_/_/_/_/_/_/.
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

/// <summary>
/// Trigger a Event with Args.
/// At this Node , if ViNoEventManager exists in your scene , ViNoEventManager
/// Send a Message to the EventReceiver.
/// </summary>
[AddComponentMenu("ViNo/Nodes/System/TriggerEventWithArgs")]
[ System.Serializable ]
public class EventTriggerWithArgsNode : ViNode {
	public string sendMessage = "";

	[System.Serializable]
	public class KeyAndValue
	{
		public string key;
		public string val;
	}
	public KeyAndValue[] pairs;

	void Start(){}

	public override void ToScenarioScript( ref System.Text.StringBuilder sb ){
		sb.Append ("[triggerevent eventType=" + sendMessage + " " );
		foreach (KeyAndValue pair in pairs) {
			sb.Append( pair.key + "=" + pair.val + " " );
		}
		sb.Append( "]" );
		sb.Append( System.Environment.NewLine );
	}	
	
	/// <summary>
	/// Tos the byte code.
	/// </summary>
	/// <param name='code'>
	/// Code.
	/// </param>
	public override void ToByteCode( ByteCodes code ){					
		List<byte> byteList = new List<byte>();
		
		AddNodeCode( byteList );

		Hashtable args = new Hashtable();
		foreach( KeyAndValue pair in pairs ){
			args [pair.key] = pair.val;
		}
		
		ByteCodeScriptTools.AddTablePairsCode( byteList , args );
		ByteCodeScriptTools.AddMessagingCode( byteList , " " , OpcodeMessaging.TRIGGER_EVENT_WITH_ARGS );
		
		code.Add( byteList.ToArray() );		
		
		// ToByteCode this Children.
		ToByteCodeInternal( code );		
	}
}



